<?php
namespace app\api\controller;

use app\api\controller\Authbase;
use app\api\model\ButtonModel;
use app\api\model\BasicConfigModel;
use think\Controller;

/**
 * 通用配置
 */
class BasicConfig extends Authbase
{
    /**
     * 获取配置信息
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function view() {
        $app_id = input('app_id/d', '');
        if (empty($app_id)) {
            return json(['code' => 0, 'error' => 'app_id 缺失']);
        }
        $field = $this->request->post();
        $field = isset($field['field'])?$field['field']:null;

        if ($field && !is_array($field)) {
            return json(['code' => 0, 'error' => 'field 必须是json格式']);
        } elseif($field && is_array($field)) {
            $field = array_values($field);
        }

        if (!$config =BasicConfigModel::config($app_id, $field)) {
            return json(['code' => 0, 'msg' => '请前往后台先配置']);
        }
        return json(['code' => 1, 'msg' => 'success', 'data' => $config]);
    }

}